/**********************************************************************
*  Copyright (c) 2007 - Victor Jacobs - victor.jacobs@gmail.com
*
*  Permission is hereby granted, free of charge, to any person
*  obtaining a copy of this software and associated documentation
*  files (the "Software"), to deal in the Software without
*  restriction, including without limitation the rights to use,
*  copy, modify, merge, publish, distribute, sublicense, and/or sell
*  copies of the Software, and to permit persons to whom the
*  Software is furnished to do so, subject to the following
*  conditions:
*
*  The above copyright notice and this permission notice shall be
*  included in all copies or substantial portions of the Software.
*
*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
*  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
*  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
*  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
*  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
*  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
*  OTHER DEALINGS IN THE SOFTWARE.
**********************************************************************/

using System;
using System.Collections.Generic;
using System.Text;

namespace Vj.Ann
{
    public class SigmoidFunction
    {
        private double minimum;
        private double maximum;
        private double slope;
        private double gamma;
        private double nu;

        public SigmoidFunction(double minimum, double maximum, double slope)
        {
            this.minimum = minimum;
            this.maximum = maximum;
            this.slope = slope;

            gamma = maximum - minimum;
            nu = -minimum;
        }

        public double Minimum
        {
            get { return minimum; }
            set
            {
                minimum = value;
                gamma = maximum - minimum;
                nu = -minimum;
            }
        }

        public double Maximum
        {
            get { return maximum; }
            set
            {
                maximum = value;
                gamma = maximum - minimum;
            }
        }

        public double Slope
        {
            get { return slope; }
            set { slope = value; }
        }

        public double Gamma
        {
            get { return gamma; }
        }

        public double Nu
        {
            get { return nu; }
        }

        public double Sigmoid(double value)
        {
            return gamma * (1.0f / (1.0f + Math.Exp(-slope * value))) - nu;
        }

        public double FirstDerivativeSigmoid(double value)
        {
            double sigmoidValue;

            sigmoidValue = Sigmoid(value);
            return (slope / gamma) * (nu + sigmoidValue) * (gamma - nu - sigmoidValue);
        }

    }
}
